from django.contrib.auth.models import AbstractUser
from django.db import models


# from apps.food.models import Foods


class User(AbstractUser):
    """自定义用户模型类"""
    openid = models.CharField(max_length=100, unique=True, verbose_name='微信标识id', db_index=True)
    user_img = models.CharField(max_length=200, default='', null=True, blank=True, verbose_name='用户头像')

    class Meta:
        db_table = 'cp_user'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 用户评论表
class UserComment(models.Model):
    food = models.ForeignKey("food.Foods", on_delete=models.PROTECT, verbose_name='评论的菜品')
    comment = models.TextField(verbose_name="评论内容", default="")
    is_child = models.ForeignKey("self", verbose_name="是否是子评论", null=True)
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'cp_user_comment'
        verbose_name = '菜品评论'
        verbose_name_plural = verbose_name


# 用户点赞表
class UserLike(models.Model):
    food = models.ForeignKey("food.Foods", on_delete=models.PROTECT, verbose_name='点赞的菜品')
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    is_del = models.BooleanField(default=False, verbose_name='该菜品点赞是否删除')

    class Meta:
        db_table = 'cp_user_like'
        verbose_name = '菜品点赞'
        verbose_name_plural = verbose_name


# 用户收藏表
class UserCollect(models.Model):
    food = models.ForeignKey("food.Foods", on_delete=models.PROTECT, verbose_name='收藏的菜品')
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    is_del = models.BooleanField(default=False, verbose_name='该菜品收藏是否删除')

    class Meta:
        db_table = 'cp_user_collect'
        verbose_name = '菜品收藏'
        verbose_name_plural = verbose_name


# 用户评论点赞表
class UserCommentLike(models.Model):
    comment = models.ForeignKey(UserComment, on_delete=models.PROTECT, verbose_name='点赞的评论')
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    is_del = models.BooleanField(default=False, verbose_name='该条评论的点赞是否删除')

    class Meta:
        db_table = 'cp_user_comment_like'
        verbose_name = '用户评论点赞'
        verbose_name_plural = verbose_name


class FeedBack(models.Model):
    name = models.CharField(verbose_name="用户反馈类型", max_length=50)

    class Meta:
        db_table = 'cp_feedback'
        verbose_name = '用户反馈类型'
        verbose_name_plural = verbose_name


class UserFeedBack(models.Model):
    connet = models.TextField(verbose_name="用户反馈内容")
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    phone = models.CharField(verbose_name="用户手机号", max_length=11)
    feedback = models.ForeignKey(FeedBack, on_delete=models.PROTECT, verbose_name="反馈类型")
    is_solve = models.BooleanField(default=False, verbose_name='该反馈是否解决')

    class Meta:
        db_table = 'cp_user_feedback'
        verbose_name = '用户反馈'
        verbose_name_plural = verbose_name
